//
//  AppDataManager.m
//  AppData
//
//  Created by CPX on 2018/5/23.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "AppDataManager.h"

NSString  * const AppLayoutDirectionChangeNotification = @"direction_layout_change";
NSString  * const PrayTimeAlgorithmChangedNotification = @"praytime_algorithm_change";

#define FirstOpen @"first_open"
#define APPUUIDString @"uuid_string"

/**
 应用全局数据类
 @author yzl
 */
@interface AppDataManager()

@property (nonatomic,strong) NSUserDefaults *defaults;

@end

@implementation AppDataManager

+ (void)registerApp{
    [self sharedManager];
}

+ (instancetype)sharedManager{
    static AppDataManager *mgr = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        mgr = [self new];
        [mgr _init];
    });
    return mgr;
}

- (void)_init{
    //12小时 24小时制式
    NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
    NSRange containsA = [formatStringForHours rangeOfString:@"a"];
    BOOL hasAMPM = containsA.location != NSNotFound;
    if(hasAMPM){
        self.timeFormat = kAppTime12AMPM;
    }
    else{
        self.timeFormat = kAppTime24;
    }
    
    id obj = [[NSUserDefaults standardUserDefaults] objectForKey:FirstOpen];
    if (!obj) {
        self.isFirstOpen = YES;
    }
    else{
        self.isFirstOpen = NO;
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:FirstOpen];
    }
    self.uuid = [[NSUserDefaults standardUserDefaults] stringForKey:APPUUIDString];
    if (!self.uuid) {
        self.uuid = [NSUUID UUID].UUIDString;
        [[NSUserDefaults standardUserDefaults] setObject:self.uuid forKey:APPUUIDString];
    }
    
    
}

@end
